/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.qxypt.io
 *
 * 版权所有，侵权必究！
 */

package xw.qxypt.modules.job.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xw.qxypt.modules.baseinfo.entity.LhpDataRoadDetectorEntity;
import xw.qxypt.modules.baseinfo.entity.LhpDataVisibilityEntity;
import xw.qxypt.modules.baseinfo.entity.LhpDataWeatherStationEntity;
import xw.qxypt.modules.baseinfo.service.LhpDataRoadDetectorService;
import xw.qxypt.modules.baseinfo.service.LhpDataVisibilityService;
import xw.qxypt.modules.baseinfo.service.LhpDataWeatherStationService;

import java.util.Calendar;
import java.util.List;

/**
 * 删除三天前的数据定时任务
 *
 * testTask为spring bean的名称
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component("removeDataTask")
public class RemoveDataTask implements ITask {
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private LhpDataWeatherStationService weatherStationService;
	@Autowired
	private LhpDataVisibilityService visibilityService;
	@Autowired
	private LhpDataRoadDetectorService roadDetectorService;


	@Override
	public void run(String params){
		logger.debug("删除数据定时任务正在执行，参数为：{}", params	);
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_YEAR, -3);
		weatherStationService.remove(
				new QueryWrapper<LhpDataWeatherStationEntity>()
						.le("data_time",c.getTime())
		);
		visibilityService.remove(
				new QueryWrapper<LhpDataVisibilityEntity>()
						.le("data_time",c.getTime())
		);
		roadDetectorService.remove(
				new QueryWrapper<LhpDataRoadDetectorEntity>()
						.le("data_time",c.getTime())
		);

	}
}
